package com.ls.listremove;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class ListRemove {

	@Test
	public void listRemove(){
		List<String> list = Lists.newArrayList("a","b","c");
		Iterator<String> iter = list.iterator();
		while(iter.hasNext()){
			String v = iter.next();
			if(v.equals("b"))
				iter.remove();
		}
		System.out.println(list);
	}
	@Test
	public void listforRemove(){
		List<String> list = Lists.newArrayList("a","b","c");
		for(String a :list){
			if(a.equals("b"))
				list.remove(a);
		}
		System.out.println(list);
	}
	
	@Test
	public void mapRemove(){
		Map<String,String> map = Maps.newHashMap();
		map.put("a", "aa");
		map.put("b", "bb");
		map.put("c", "cc");
		map.put("d", "dd");
		for(String k:map.keySet()){
			if(k.equalsIgnoreCase("b"))
				map.remove(k);
		}
	}
	
	@Test
	public void mapIterRemove(){
		Map<String,String> map = Maps.newHashMap();
		map.put("a", "aa");
		map.put("b", "bb");
		map.put("c", "cc");
		map.put("d", "dd");
		 Set<Entry<String, String>> entry = map.entrySet();
		 Iterator<Entry<String, String>> iter = entry.iterator();
		 while(iter.hasNext()){
			 Entry<String, String> a = iter.next();
			 if(a.getValue().equals("bb"))
				 iter.remove();
		 }
	}
}
